$(function () {
    let form = layui.form
    form.verify({
        Pwd: [
            /^[\S]{6,12}$/,
            '必须是6到12位非空字符串'
        ],
        newPwd: function (value) {
            let v1 = $('[name = oldPwd]').val()
            if (value == v1) {
                return "原密码和新密码不能相同"
            }
        },
        rePwd: function (value) {
            let v2 = $('[name = newPwd]').val()
            if (value != v2) {
                return "两次密码必须保持一致"
            }
        }
    })
    $('#forPwd').on('submit', function (e) {
        e.preventDefault()
        axios({
            url:'/my/updatepwd',
            method:'post',
            data: $(this).serialize()
        }).then(res=>{
            //成功回调
            if (res.data.status != 0) {
               return layui.layer.msg(res.data.message)
            }
            layui.layer.msg('恭喜修改成功')
            $('#forPwd')[0].reset()
            setTimeout(function(){
                window.parent.location.href='/login.html' 
            },200)
        });
    })
})